#include <iostream>
#include <vector>
#include <string>
#include <cmath>
using  std::cout, std::cin, std::endl;
int prev, next;

int main()
{   
    int n;
    cin >> n;
    int a = 0, b = 1;
    int c = 0;
    while (c < n)
    {
        prev = c;
        c = a + b;
        a = b;
        b = c;
    }
    cout << std::min(fabs(prev - n), fabs(c - n));
    return 0;
}